package models

import (
	"jlpay-sdk-go/pkg/jlpay/core"
)

// ==================== 延期资金管控查询 ====================

// DeferredActivationQueryRequest 延期资金管控查询请求
type DeferredActivationQueryRequest struct {
	OrgBaseRequest
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewDeferredActivationQueryRequest 创建延期资金管控查询请求
func NewDeferredActivationQueryRequest() *DeferredActivationQueryRequest {
	req := &DeferredActivationQueryRequest{}
	return req
}

// SetRawRequestMap 设置原始请求映射数据
func (r *DeferredActivationQueryRequest) SetRawRequestMap(rawMap map[string]interface{}) *DeferredActivationQueryRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *DeferredActivationQueryRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *DeferredActivationQueryRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *DeferredActivationQueryRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// DeferredActivationQueryResponse 延期资金管控查询响应
type DeferredActivationQueryResponse struct {
	StandardResponse
	// Status 状态
	Status string `json:"status,omitempty"`
	// OpenTime 开通时间
	OpenTime string `json:"open_time,omitempty"`
	// CloseTime 关停时间
	CloseTime string `json:"close_time,omitempty"`
}

// NewDeferredActivationQueryResponse 创建延期资金管控查询响应
func NewDeferredActivationQueryResponse() *DeferredActivationQueryResponse {
	return &DeferredActivationQueryResponse{}
}

// ==================== 延期资金管控开通 ====================

// DeferredActivationOpenRequest 延期资金管控开通请求
type DeferredActivationOpenRequest struct {
	OrgBaseRequest
	// AgreementPic 协议图片
	AgreementPic string `json:"agreement_pic,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewDeferredActivationOpenRequest 创建延期资金管控开通请求
func NewDeferredActivationOpenRequest() *DeferredActivationOpenRequest {
	req := &DeferredActivationOpenRequest{}
	return req
}

// SetAgreementPic 设置协议图片
func (r *DeferredActivationOpenRequest) SetAgreementPic(agreementPic string) *DeferredActivationOpenRequest {
	r.AgreementPic = agreementPic
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *DeferredActivationOpenRequest) SetRawRequestMap(rawMap map[string]interface{}) *DeferredActivationOpenRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *DeferredActivationOpenRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *DeferredActivationOpenRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.AgreementPic != "" {
		baseMap["agreement_pic"] = r.AgreementPic
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *DeferredActivationOpenRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// DeferredActivationOpenResponse 延期资金管控开通响应
type DeferredActivationOpenResponse struct {
	StandardResponse
	// 只包含 ret_code 和 ret_msg，继承自 StandardResponse
}

// NewDeferredActivationOpenResponse 创建延期资金管控开通响应
func NewDeferredActivationOpenResponse() *DeferredActivationOpenResponse {
	return &DeferredActivationOpenResponse{}
}

// ==================== 延期资金管控关停 ====================

// DeferredActivationCloseRequest 延期资金管控关停请求
type DeferredActivationCloseRequest struct {
	OrgBaseRequest
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewDeferredActivationCloseRequest 创建延期资金管控关停请求
func NewDeferredActivationCloseRequest() *DeferredActivationCloseRequest {
	req := &DeferredActivationCloseRequest{}
	return req
}

// SetRawRequestMap 设置原始请求映射数据
func (r *DeferredActivationCloseRequest) SetRawRequestMap(rawMap map[string]interface{}) *DeferredActivationCloseRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *DeferredActivationCloseRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *DeferredActivationCloseRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *DeferredActivationCloseRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// DeferredActivationCloseResponse 延期资金管控关停响应
type DeferredActivationCloseResponse struct {
	StandardResponse
	// 只包含 ret_code 和 ret_msg，继承自 StandardResponse
}

// NewDeferredActivationCloseResponse 创建延期资金管控关停响应
func NewDeferredActivationCloseResponse() *DeferredActivationCloseResponse {
	return &DeferredActivationCloseResponse{}
}

// ==================== 资金流水查询 ====================

// FundFlowQueryRequest 资金流水查询请求
type FundFlowQueryRequest struct {
	OrgBaseRequest
	// OutOrderID 外部订单ID
	OutOrderID string `json:"out_order_id,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewFundFlowQueryRequest 创建资金流水查询请求
func NewFundFlowQueryRequest() *FundFlowQueryRequest {
	req := &FundFlowQueryRequest{}
	return req
}

// SetOutOrderID 设置外部订单ID
func (r *FundFlowQueryRequest) SetOutOrderID(outOrderID string) *FundFlowQueryRequest {
	r.OutOrderID = outOrderID
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *FundFlowQueryRequest) SetRawRequestMap(rawMap map[string]interface{}) *FundFlowQueryRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *FundFlowQueryRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *FundFlowQueryRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.OutOrderID != "" {
		baseMap["out_order_id"] = r.OutOrderID
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *FundFlowQueryRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// FundFlowQueryResponse 资金流水查询响应
type FundFlowQueryResponse struct {
	StandardResponse
	// OutOrderID 外部订单ID
	OutOrderID string `json:"out_order_id,omitempty"`
	// OriOutOrderID 原外部订单ID
	OriOutOrderID string `json:"ori_out_order_id,omitempty"`
	// TransactionID 交易ID
	TransactionID string `json:"transaction_id,omitempty"`
	// MerchNo 商户号
	MerchNo string `json:"merch_no,omitempty"`
	// OrderType 订单类型
	OrderType string `json:"order_type,omitempty"`
	// FreezeAmount 冻结金额
	FreezeAmount string `json:"freeze_amount,omitempty"`
	// UnfreezeAmount 解冻金额
	UnfreezeAmount string `json:"unfreeze_amount,omitempty"`
	// Status 状态
	Status string `json:"status,omitempty"`
	// FailureReason 失败原因
	FailureReason string `json:"failure_reason,omitempty"`
	// FreezeTime 冻结时间
	FreezeTime string `json:"freeze_time,omitempty"`
	// UnfreezeTime 解冻时间
	UnfreezeTime string `json:"unfreeze_time,omitempty"`
	// Reason 原因
	Reason string `json:"reason,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
}

// NewFundFlowQueryResponse 创建资金流水查询响应
func NewFundFlowQueryResponse() *FundFlowQueryResponse {
	return &FundFlowQueryResponse{}
}

// ==================== 资金冻结 ====================

// FundFreezeRequest 资金冻结请求
type FundFreezeRequest struct {
	OrgBaseRequest
	// OutOrderID 外部订单ID
	OutOrderID string `json:"out_order_id,omitempty"`
	// TransactionID 交易ID
	TransactionID string `json:"transaction_id,omitempty"`
	// FreezeAmount 冻结金额
	FreezeAmount string `json:"freeze_amount,omitempty"`
	// Reason 冻结原因
	Reason string `json:"reason,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewFundFreezeRequest 创建资金冻结请求
func NewFundFreezeRequest() *FundFreezeRequest {
	req := &FundFreezeRequest{}
	return req
}

// SetOutOrderID 设置外部订单ID
func (r *FundFreezeRequest) SetOutOrderID(outOrderID string) *FundFreezeRequest {
	r.OutOrderID = outOrderID
	return r
}

// SetTransactionID 设置交易ID
func (r *FundFreezeRequest) SetTransactionID(transactionID string) *FundFreezeRequest {
	r.TransactionID = transactionID
	return r
}

// SetFreezeAmount 设置冻结金额
func (r *FundFreezeRequest) SetFreezeAmount(freezeAmount string) *FundFreezeRequest {
	r.FreezeAmount = freezeAmount
	return r
}

// SetReason 设置冻结原因
func (r *FundFreezeRequest) SetReason(reason string) *FundFreezeRequest {
	r.Reason = reason
	return r
}

// SetRemark 设置备注
func (r *FundFreezeRequest) SetRemark(remark string) *FundFreezeRequest {
	r.Remark = remark
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *FundFreezeRequest) SetRawRequestMap(rawMap map[string]interface{}) *FundFreezeRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *FundFreezeRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *FundFreezeRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.OutOrderID != "" {
		baseMap["out_order_id"] = r.OutOrderID
	}
	if r.TransactionID != "" {
		baseMap["transaction_id"] = r.TransactionID
	}
	if r.FreezeAmount != "" {
		baseMap["freeze_amount"] = r.FreezeAmount
	}
	if r.Reason != "" {
		baseMap["reason"] = r.Reason
	}
	if r.Remark != "" {
		baseMap["remark"] = r.Remark
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *FundFreezeRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// FundFreezeResponse 资金冻结响应
type FundFreezeResponse struct {
	StandardResponse
	// 只包含 ret_code 和 ret_msg，继承自 StandardResponse
}

// NewFundFreezeResponse 创建资金冻结响应
func NewFundFreezeResponse() *FundFreezeResponse {
	return &FundFreezeResponse{}
}

// ==================== 资金解冻 ====================

// FundUnfreezeRequest 资金解冻请求
type FundUnfreezeRequest struct {
	OrgBaseRequest
	// OutOrderID 外部订单ID
	OutOrderID string `json:"out_order_id,omitempty"`
	// OriOutOrderID 原外部订单ID
	OriOutOrderID string `json:"ori_out_order_id,omitempty"`
	// UnfreezeAmount 解冻金额
	UnfreezeAmount string `json:"unfreeze_amount,omitempty"`
	// Reason 解冻原因
	Reason string `json:"reason,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewFundUnfreezeRequest 创建资金解冻请求
func NewFundUnfreezeRequest() *FundUnfreezeRequest {
	req := &FundUnfreezeRequest{}
	return req
}

// SetOutOrderID 设置外部订单ID
func (r *FundUnfreezeRequest) SetOutOrderID(outOrderID string) *FundUnfreezeRequest {
	r.OutOrderID = outOrderID
	return r
}

// SetOriOutOrderID 设置原外部订单ID
func (r *FundUnfreezeRequest) SetOriOutOrderID(oriOutOrderID string) *FundUnfreezeRequest {
	r.OriOutOrderID = oriOutOrderID
	return r
}

// SetUnfreezeAmount 设置解冻金额
func (r *FundUnfreezeRequest) SetUnfreezeAmount(unfreezeAmount string) *FundUnfreezeRequest {
	r.UnfreezeAmount = unfreezeAmount
	return r
}

// SetReason 设置解冻原因
func (r *FundUnfreezeRequest) SetReason(reason string) *FundUnfreezeRequest {
	r.Reason = reason
	return r
}

// SetRemark 设置备注
func (r *FundUnfreezeRequest) SetRemark(remark string) *FundUnfreezeRequest {
	r.Remark = remark
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *FundUnfreezeRequest) SetRawRequestMap(rawMap map[string]interface{}) *FundUnfreezeRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *FundUnfreezeRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *FundUnfreezeRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.OutOrderID != "" {
		baseMap["out_order_id"] = r.OutOrderID
	}
	if r.OriOutOrderID != "" {
		baseMap["ori_out_order_id"] = r.OriOutOrderID
	}
	if r.UnfreezeAmount != "" {
		baseMap["unfreeze_amount"] = r.UnfreezeAmount
	}
	if r.Reason != "" {
		baseMap["reason"] = r.Reason
	}
	if r.Remark != "" {
		baseMap["remark"] = r.Remark
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *FundUnfreezeRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// FundUnfreezeResponse 资金解冻响应
type FundUnfreezeResponse struct {
	StandardResponse
	// 只包含 ret_code 和 ret_msg，继承自 StandardResponse
}

// NewFundUnfreezeResponse 创建资金解冻响应
func NewFundUnfreezeResponse() *FundUnfreezeResponse {
	return &FundUnfreezeResponse{}
}

// ==================== 资金续冻 ====================

// FundRefreezeRequest 资金续冻请求
type FundRefreezeRequest struct {
	OrgBaseRequest
	// OutOrderID 外部订单ID
	OutOrderID string `json:"out_order_id,omitempty"`
	// OriOutOrderID 原外部订单ID
	OriOutOrderID string `json:"ori_out_order_id,omitempty"`
	// Reason 续冻原因
	Reason string `json:"reason,omitempty"`
	// Remark 备注
	Remark string `json:"remark,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewFundRefreezeRequest 创建资金续冻请求
func NewFundRefreezeRequest() *FundRefreezeRequest {
	req := &FundRefreezeRequest{}
	return req
}

// SetOutOrderID 设置外部订单ID
func (r *FundRefreezeRequest) SetOutOrderID(outOrderID string) *FundRefreezeRequest {
	r.OutOrderID = outOrderID
	return r
}

// SetOriOutOrderID 设置原外部订单ID
func (r *FundRefreezeRequest) SetOriOutOrderID(oriOutOrderID string) *FundRefreezeRequest {
	r.OriOutOrderID = oriOutOrderID
	return r
}

// SetReason 设置续冻原因
func (r *FundRefreezeRequest) SetReason(reason string) *FundRefreezeRequest {
	r.Reason = reason
	return r
}

// SetRemark 设置备注
func (r *FundRefreezeRequest) SetRemark(remark string) *FundRefreezeRequest {
	r.Remark = remark
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *FundRefreezeRequest) SetRawRequestMap(rawMap map[string]interface{}) *FundRefreezeRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *FundRefreezeRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *FundRefreezeRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.OutOrderID != "" {
		baseMap["out_order_id"] = r.OutOrderID
	}
	if r.OriOutOrderID != "" {
		baseMap["ori_out_order_id"] = r.OriOutOrderID
	}
	if r.Reason != "" {
		baseMap["reason"] = r.Reason
	}
	if r.Remark != "" {
		baseMap["remark"] = r.Remark
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *FundRefreezeRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// FundRefreezeResponse 资金续冻响应
type FundRefreezeResponse struct {
	StandardResponse
	// 只包含 ret_code 和 ret_msg，继承自 StandardResponse
}

// NewFundRefreezeResponse 创建资金续冻响应
func NewFundRefreezeResponse() *FundRefreezeResponse {
	return &FundRefreezeResponse{}
}
